package dav.mobile.garuda.states.game;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;

//Simple game object with position
public abstract class GameObject {
	//Position
	protected Vector2	m_Position;
	
	//Texture region
	protected TextureRegion m_Texture;
	
	//Default constructor
	protected GameObject(int x, int y, TextureRegion texture) {
		//Set position
		m_Position = new Vector2(x, y);
		
		//Set texture region
		m_Texture = texture;
	}
	
	//Custom constructor for runtime texture
	protected GameObject(int x, int y) {
		//Set position
		m_Position = new Vector2(x, y);
		
		//Set texture region
		m_Texture = null;
	}
	
	//Getter-Setter
	public Vector2 	getPosition() 		{ return m_Position;   								}
	public float	getPosX()			{ return m_Position.x; 								}
	public float	getPosY()			{ return m_Position.y; 								}
	public int		getWidth()			{ return Math.abs(m_Texture.getRegionWidth());		}
	public int		getHeight()			{ return Math.abs(m_Texture.getRegionHeight()); 	}
	
	//Abstract attribute
	public abstract void Update(float deltatime);
	public abstract void Render(SpriteBatch m_Spritebatch);
	
	//static method for collision
	public static boolean DoesAABBHit(GameObject a, GameObject b) {
		//Init
		float aX = a.getPosX() + (float) a.getWidth();
		float aY = a.getPosY() + (float) a.getHeight();
		float bX = b.getPosX() + (float) b.getWidth();
		float bY = b.getPosY() + (float) b.getHeight();
		
		//System.out.println(a.getPosX() + " " + aX + " " +  b.getPosX() + " " + bX);
		//System.out.println(a.getPosY() + " " + aY + " " +  b.getPosY() + " " + bY);
		
		//Check collision and return
		return !(a.getPosX()>bX||aX<b.getPosX()||a.getPosY()>bY||aY<b.getPosY());
	}
}
